package com.reagent.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reagent.response.Result;
import com.reagent.system.entity.Type;
import com.reagent.system.mapper.TypeMapper;
import com.reagent.system.service.TypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
@Slf4j
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService {

    @Resource
    private TypeMapper typeMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Object getTypeAll() {
        List<Type> list = typeMapper.selectList(new QueryWrapper<Type>().select("*"));
        if (!ObjectUtils.isEmpty(list)) {
            log.info("获取类别信息成功");
            return Result.success().message("获取类别信息成功").data(list);
        }
        log.error("获取类别信息失败");
        return Result.success().message("获取类别信息失败");
    }
}
